
_realname=igraph
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.9.0
pkgrel=1
pkgdesc="Library for the analysis of networks (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://igraph.org"
license=('GPL')
source=("https://github.com/igraph/igraph/releases/download/${pkgver}/igraph-${pkgver}.tar.gz"
        '0001-igraph-0.9.0-link-libm-only-when-needed.patch')
sha256sums=('012e5d5a50420420588c33ec114c6b3000ccde544db3f25c282c1931c462ad7a'
            'c84862f28bf07b145eeb3c2ebe65e1a8c5efadb1513cb8f897934f9c95244bd2')
depends=("${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")

_srcdir=${_realname}-${pkgver}
_builddir=build-${pkgver}-${MINGW_PACKAGE_PREFIX}

prepare() {
  cd ${_srcdir}
  patch -p1 -b -i "${srcdir}/0001-igraph-0.9.0-link-libm-only-when-needed.patch"
}

build() {
  mkdir -p ${_builddir}
  pushd ${_builddir}
    MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake ../${_srcdir} \
      -G 'MSYS Makefiles' \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      -DCMAKE_BUILD_TYPE=Release \
      -DIGRAPH_GLPK_SUPPORT=1 \
      -DIGRAPH_GRAPHML_SUPPORT=1 \
      -DIGRAPH_VERIFY_FINALLY_STACK=1 \
      -DIGRAPH_USE_INTERNAL_ARPACK=1 \
      -DIGRAPH_USE_INTERNAL_BLAS=1 \
      -DIGRAPH_USE_INTERNAL_CXSPARSE=1 \
      -DIGRAPH_USE_INTERNAL_GLPK=1 \
      -DIGRAPH_USE_INTERNAL_GMP=1 \
      -DIGRAPH_USE_INTERNAL_LAPACK=1

    make || make VERBOSE=1
  popd
}

check() {
  # igraph 0.9.0: all tests succeeded
  pushd ${_builddir}
    make build_tests
    ${MINGW_PREFIX}/bin/ctest --output-on-failure
  popd
}

package() {
  make -C ${_builddir} DESTDIR="${pkgdir}" install
  install -D -m644 ${_srcdir}/COPYING "${pkgdir}"/${MSYSTEM_PREFIX}/share/licenses/${_realname}/COPYING
}
